package com.dykj.fireFighting.server.socialUnit.devicemanger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dykj.fireFighting.api.socialUnit.devicemanger.entity.Manufactor;
import com.dykj.fireFighting.api.socialUnit.devicemanger.service.IManufactorService;
import com.dykj.fireFighting.common.core.dto.CommonDto;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.server.socialUnit.devicemanger.mapper.ManufactorMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * 主机管理
 *
 * @Author aixiaolan
 * @Date 2021-06-15 15:50:59
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class ManufactorServiceImpl extends BaseServiceImpl<ManufactorMapper, Manufactor> implements IManufactorService {

    @Autowired
    private ManufactorMapper manufactorMapper;

    @Override
    public List<Manufactor> queryBySysType(String unitId, String deviceSysType) {
        QueryWrapper<Manufactor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("unit_id", unitId);
        queryWrapper.eq("system_type", deviceSysType);
        return manufactorMapper.selectList(queryWrapper);
    }

    @Override
    public PageVo<Manufactor> queryList(CommonDto commonDto) {
        HashMap<String, Object> params = new HashMap<>(16);
        Page page = new Page();
        // 设置当前页码
        page.setCurrent(commonDto.getPage());
        // 设置页大小
        page.setSize(commonDto.getLimit());
        return new PageVo<Manufactor>(this.baseMapper.queryList(page, params));
    }

    @Override
    public int countTotal(String s) {
        QueryWrapper<Manufactor> wrapper = new QueryWrapper<>();
        wrapper.eq("unit_id", s)
                .eq("is_online", "1");
        return this.baseMapper.selectCount(wrapper).intValue();
    }
}
